# !/user/bin/env python3
# -*- coding:utf-8 -*-


import requests


def test_1():
    files = {'file': open('favicon.ico', 'rb')}
    r = requests.post('http://httpbin.org/post', files=files)
    print(r.json())


def test_2():
    """获取cookie"""
    r = requests.get('https://www.baidu.com')
    print(r.cookies)
    for key, value in r.cookies.items():
        print(key + '=' + value)


def test_3():
    """使用session维持会话"""
    s = requests.Session()
    s.get('http://httpbin.org/cookies/set/number/123456789')
    r = s.get('http://httpbin.org/cookies')
    print(r.text)


if __name__ == '__main__':
    test_3()
